<%@page import="com.sinodata.bsm.center.cache.PropertyValueCache"%>
<%@page import="com.sinodata.bsm.center.bean.ResBean"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.service.resource.ResService"%>
<%@page import="com.sinodata.bsm.center.service.config.PortalService"%>
<%@ page import="com.sinodata.bsm.common.vo.*"%>
<%@ page import="com.sinodata.bsm.common.utils.*"%>
<%@ page import="com.sinodata.bsm.center.bean.*"%>
<%
ResService service = SpringContextHolder.getBean(ResService.class);
PortalService sqlservice = SpringContextHolder.getBean(PortalService.class);
String resid = request.getParameter("resid");
Res  res = service.get(Long.parseLong(resid));
String pageno = request.getParameter("pageno");
if(pageno==null)pageno="1";
String str = "<chart  bgColor='#ecf6fc' bgAlpha='100' showTickValues='1'  showBorder='0'  lowerLimit='0' fontcolor='000000' upperLimit='100' ";
str += " majorTMColor='FFFFFF' majorTMAlpha='1' majorTMNumber='6' minorTMNumber='0' ";
str += " tickValueStep='1'    tickValueDistance='10'   showTickMarks='1'  showBorder='0' basefontColor='000000' ";
str += " chartTopMargin='5' chartLeftMargin='1' chartBottomMargin='5' gaugeInnerRadius='0' gaugeOuterRadius='60' fillAngle='50' chartLeftMargin='0' chartRightMargin='0' ";
str += " toolTipBgColor='80A905' > ";
str += "<colorRange>";
str += "<color minValue='0' maxValue='20' code='#ce110f' />";
str += "<color minValue='20' maxValue='40' code='#ff9937' />";
str += "<color minValue='41' maxValue='60' code='#dede03' />";
str += "<color minValue='61' maxValue='80' code='#56a8f4' />";
str += "<color minValue='81' maxValue='100' code='#2cb900' />";
str += "</colorRange>";
str += "<dials>";
//str += "<dial value = '" + healthDegree + "' rearExtension='10' />";
int degree =res.getHealthDegree();
str += "<dial value = '"+degree+"' rearExtension='10' radius='55' link='' />";
str += "</dials>";
str += "</chart>";

	PropertyValueCache propertyValueCache = SpringContextHolder.getBean(PropertyValueCache.class);
	ResBean resBean = ResBean.get(Long.valueOf(resid));
	ResBean[] resArray = resBean.children();
	ResTypeBean bean = null;
	List<Res> resList = new ArrayList<Res>();
	String resIds ="";
	//select t.resid,t.PROP1 from property_value t where t.time > sysdate-1 and resid in()
	boolean flag = false;
	Map<String,Integer[]> map = new HashMap<String,Integer[]>();
	for(ResBean b :resArray){
	   if((bean =b.type().parent())!=null && bean.resType().getId()==1105060000000L){
	       resList.add(b.res());
	    	map.put(String.valueOf(b.res().getId()),new Integer[]{0,0});
	       if(flag){
	           resIds+=","+b.res().getId();
	       }else{
	           resIds=""+b.res().getId();
	           flag = true;
	       }
	   }
	}
	String sql = "select t.resid RESID,t.PROP52 VAL from property_value t where t.time > sysdate-1 and resid in("+resIds+")";
	List<Map<String,Object>>  list = new ArrayList<Map<String,Object>>(0);
	if(resIds!=null  && !resIds.equals("")){
	     list = sqlservice.findListBySql(sql.toString());
	}
	for(int i=0; list!=null && i<list.size(); i++){
	    Map<String,Object> tmpMap = list.get(i);
	    String strId  =tmpMap.get("RESID").toString();
	    String strVal = "0";
	    if(tmpMap.get("VAL")!=null){
	         strVal = tmpMap.get("VAL").toString();
	    }
	    
	    Integer[] vals =map.get(strId);
	    vals[1]=vals[1]+1;
	 	if(strVal.equals("1")){
	     	vals[0]=vals[0]+1;
	    }
	}
	Map<Long,String> fusionMap = new HashMap<Long,String>();
	for(int i = 0;i<resList.size();i++){
	    Res res1 = resList.get(i);
	    Integer[] vals = map.get(res1.getId().toString());
	    int  m = (int)(vals[0].floatValue()*100/vals[1].floatValue());
	   	String chengglStr = "<Chart bgColor='ecf6fc' bgAlpha='100' showBorder='0' chartTopMargin='9' chartLeftMargin='1' chartBottomMargin='0' gaugeFillMix='{light-1},{light-1},{light-1},{dark-1},{dark-1}, {dark-1}' upperLimit='100' lowerLimit='0' baseFontColor='000000' baseFontSize='9' tickValueDistance='7' majorTMNumber='6' majorTMColor='FFFFFF'  majorTMHeight='6' minorTMNumber='6' minorTMColor='efeaea' minorTMHeight='3' toolTipBorderColor='cccccc' toolTipBgColor='cccccc' gaugeOuterRadius='45' gaugeOriginX='50' gaugeOriginY='50' gaugeScaleAngle='270' placeValuesInside='1' gaugeInnerRadius='78%22' annRenderDelay='0' gaugeFillMix='' pivotRadius='5' showPivotBorder='0' pivotFillMix='{32d4c0},{069d7b}' pivotFillRatio='50,50' showShadow='0'>";
	  		chengglStr += "<colorRange>";
	  		chengglStr += "<color minValue='0' maxValue='20' code='e1221a' />";
	  		chengglStr += "<color minValue='20' maxValue='40' code='ff9937' />";
	  		chengglStr += "<color minValue='40' maxValue='60' code='dede03' />";
	  		chengglStr += "<color minValue='60' maxValue='80' code='56a8f4'/>";
	  		chengglStr += "<color minValue='80' maxValue='100' code='2cb900'/>";
	  		chengglStr += "</colorRange>";
	  		chengglStr += "<dials>";
	  		chengglStr += "<dial value='"+m+"' borderColor='000000' bgColor='069d7b,7fd2d2,069d7b' borderAlpha='3' baseWidth='10'/>";//指针
	  		chengglStr += "</dials>";
	  		chengglStr += "<annotations>";
	  		chengglStr += "<annotationGroup xPos='50' yPos='50' showBelow='1'>";
	  		chengglStr += "<annotation type='circle' xPos='0' yPos='0' radius='45' startAngle='9' endAngle='360' color='d7f7f5,a5efda'/>";//表盘
	  		chengglStr += "</annotationGroup>";
	  		chengglStr += "</annotations>";
	  		chengglStr += "</Chart>";
	  		fusionMap.put(res1.getId(),chengglStr);
	}
	int usedCount=0;
	int unusedCount=0;
%>

<script type="text/javascript">
function initTop(){
	try{
	$("#useability_div").jCarouselLite({
    		btnNext: "#next",
    		btnPrev: "#prev"
		});
	}catch(e){
	}
	try{
		var myChart = new FusionCharts("${pageContext.request.contextPath}/resources/charts/AngularGauge.swf","myChartId1", 165, 90, "0", "1");
		myChart.setDataXML("<%=str%>");
		myChart.render("yibiao");  
		<%for(int i = 0;i<resList.size();i++){
		    Res r = resList.get(i);
		%>
			 var chengglChart = new FusionCharts("${pageContext.request.contextPath}/resources/charts/AngularGauge.swf","myChartId<%=r.getId()%>", 100, 95, "0", "1");
			chengglChart.setDataXML("<%=fusionMap.get(r.getId())%>");
			chengglChart.render("chenggl_<%=r.getId()%>");
		<%}%>
	}catch(e){
	
	}
}
  function clickIt(){
  	alert("clickIt");
  }
  function FC_Rendered(domId){
  	
 		$('#'+domId).bind('click', function() {
  			alert('User clicked on "foo."');
	});
 		
  }

</script>
<!--手机银行系统监控一览-->
<!--监控一览-->
<div class="column">
	<b class="b1"></b>
	<b class="b2"></b>
	<b class="b3"></b>
	<b class="b4"></b>
	<div class="content" style="height: 200px;">
		<h2><%=res.getName() %>一览</h2>
		<ul class="x-ul">
			<li class="w-35">
				<!--健康状况-->
				<div class="jiankang">
					<h3>
						健康状况
					</h3>
					<div class="jiankang_content" id="yibiao"></div>
					<div class="jiankang_text">
						<span>当前健康状况：</span><span>警告</span>
					</div>
				</div>
				<!--@end 健康状况-->

				<!--可用性统计-->
				<div class="availability">
					<h3>
						<a href="viewanalyze-available-all.jsp?resid=<%= resid%>" target="_blank">可用性统计</a>
					</h3>
					<div class="availability_content">
						<div class="keyong">
							<img src="/bsm/style/default/bsm/appview/keyong.png" title="可用"
								width="33" height="33" />
							<span style="text-indent: 12px;">可用：</span><span class="shuzi"
								id="usedCount_span"></span>
						</div>
						<div class="bukeyong">
							<img src="/bsm/style/default/bsm/appview/bukeyong.png"
								title="不可用" width="33" height="33" />
							<span> 不可用：</span><span class="shuzi" id="unusedCount_span"></span>
						</div>
					</div>
				</div>
				<!--@end 可用性统计-->
			</li>
			<li>
				<img id="prev" style="float: left; margin: 46px 10px 0px 0px;"
					src="/bsm/style/default/bsm/appview/prev.png" />
			</li>
			<li class="w-65">
				<!--wap  iphone  andriod 登录-->
				<div class="left_ul" id="useability_div">

					<ul>
						<%for(Res r:resList){  %>
						<li>
							<h3>
								<a
									href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=r.getId() %>&pId=0&viewId=1&ntype=2"
									style="cursor: pointer; color: #091782;" target="_blank"><%=r.getName() %></a>
							</h3>
							<div class="li_content">
								<div class="li_content_left">
									<div class="top">
										<span class="left">可用状态：</span>
										<%String status = propertyValueCache.getValue(r.getId(), 110506000000002L); 
										     	  String timeStr = propertyValueCache.getValue(r.getId(), 110506000000001L); 
										     	  if(status!=null&&status.trim().equals("1")){
										     	      usedCount++;
										     %>
										<span><img src="/bsm/style/default/bsm/appview/ky.png"
												width="16" height="16" title="可用" />
										</span>
										<%}else{ 
										         unusedCount++;
										     %>
										<span><img src="/bsm/style/default/bsm/appview/bky.png"
												width="16" height="16" title="不可用" />
										</span>
										<%} %>
									</div>
									<div class="bottom">
										<span class="left">响应时长：</span>
										<span>
											<%
										        	if(timeStr!=null){
										     		    int time = Integer.parseInt(timeStr);
										     		    if(time>=10000){
										     		        time = time/1000;
										     		        out.println(time+"s");
										     		    }else{
										     		        out.println(time+"ms");
										     		    }
										     		}else{
										     		    out.println("--");
										     		}
										     %>
										</span>
									</div>
								</div>
								<div class="li_content_right" id="chenggl_<%=r.getId()%>"></div>
								<p>
									<a  href="${pageContext.request.contextPath}/appview/res-analysis!view.action?resid=<%= resid%>" target="_blank">24小时可用率</a>
								</p>
							</div>
						</li>
						<%} %>
					</ul>

				</div>
			</li>
			<li>
				<img id="next" style="float: left; margin: 46px 0px 0px 0px;"
					src="/bsm/style/default/bsm/appview/next.png" />
			</li>
		</ul>


		<!--@end wap iphone andriod 登录-->
		<br class="clear" />
	</div>
</div>
<!--@end 手机银行系统监控一览-->
<div class="column">
	<div class="tabbar">
		<ul>
			<li id="baseLi" class="<%=pageno.equals("1") ? "selected":"" %>">
				<a id="baseA" href="viewdetail1.jsp?resid=<%= resid%>"
					target="_self"><span>基础资源</span>
				</a>
			</li>
			<li id="appViewLi" class="<%=pageno.equals("2") ? "selected":"" %>">
				<a id="appViewA" href="viewdetail2.jsp?resid=<%= resid%>"
					target="_self"><span>应用环境</span>
				</a>
			</li>
			<li id="appRelLi" class="<%=pageno.equals("3") ? "selected":"" %>">
				<a id="appRelA" href="viewdetail3.jsp?resid=<%= resid%>"
					target="_self"><span>应用关联</span>
				</a>
			</li>
			<li id="eventLi" class="<%=pageno.equals("4") ? "selected":"" %>">
				<a id="eventA" href="viewdetail4.jsp?resid=<%= resid%>"
					target="_self"> <span>事件分析</span>
				</a>
			</li>
		</ul>
		<div class="clear"></div>
	</div>
</div>
<script type="text/javascript">
<!--
$("#usedCount_span").html('<%=usedCount%>');
$("#unusedCount_span").html('<%=unusedCount%>');
//-->
</script>
